/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Beans.UserRole;
import datas.UserRoleMapper;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

/**

 @author jtanguay
 */
public class UserRoleDao {

  //Recuperation des role pour un user
  public static List<UserRole> getRoleForUser(int idUser) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      UserRoleMapper mapper = session.getMapper(UserRoleMapper.class);
      List<UserRole> userRoleList = mapper.getAllRolesForUser(idUser);

      return userRoleList;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  //Mise a jour du role d'un user
  public static int upgradeUserAccount(int idRole, int idUser, int idRoleToUpgrade) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      UserRoleMapper mapper = session.getMapper(UserRoleMapper.class);
      int retour = mapper.upGradeAccount(idRole, idUser, idRoleToUpgrade);

      session.commit();

      return retour;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }
}
